<?php
namespace UserApi\Controller;
use Zend\Mvc\Controller\AbstractRestfulController;
use Zend\View\Model\JsonModel;
class ChangePasswordApiController extends AbstractRestfulController
{
    public function getList()
    {			
		header('Access-Control-Allow-Origin: *');
		$questionsTable=$this->getServiceLocator()->get('Models\Model\QuestionsFactory');
		$questionsList = $questionsTable->getTotalQuestions()->toarray();
		if(count($questionsList)!=0){
			return new JsonModel(array(
				'questionsList' 	=> json_encode($questionsList),
				'value'				=>	1,
			));
		}else{
			return new JsonModel(array(
				'output' => 'no data',
				'value'	 =>	1,
			));
		}	
    }
    public function get($course_id)
    {		
		header('Access-Control-Allow-Origin: *');
		$questionsTable=$this->getServiceLocator()->get('Models\Model\QuestionsFactory');
		$explodeId=explode('-',$course_id);
			$courseId=$explodeId[0];
			$value=$explodeId[1];
			$user_id=$explodeId[2];
			$level=$explodeId[3];
			$subject_id=$explodeId[4];
		if($user_id==0){
			$questionsList = $questionsTable->getQuestion($courseId)->toarray();
		}else{
			$questionsList = $questionsTable->getQuestionslist($courseId,$value,$user_id,$level,$subject_id)->toarray();
		}
		
		if(count($questionsList)!=0){
			return new JsonModel(array(
				'questionsList' 	=> json_encode($questionsList),
				'value'	=>	1,
			));
		}else{
			return new JsonModel(array(
				'output' => 'no data',
				'value'	=>	0,
			));
		}	
    }
    public function create($data)
    {
		header('Access-Control-Allow-Origin: *');	
    }
    public function update($admin_id,$data)
    {
		header('Access-Control-Allow-Origin: *');	
		$userTable=$this->getServiceLocator()->get('Models\Model\UsersFactory');
		$checkpassword	= $userTable->checkpassword($admin_id,$data)->toArray();
		if(count($checkpassword)!=0){
			$updateOldpassword	= $userTable->updateOldpassword($admin_id,$data['cnf_password']);
			return new JsonModel(array(
				'data' 		=> 'success',
				'value'		=>	1,
			));
		}else{
			return new JsonModel(array(
				'output' => 'fail',
				'value'	=>	0,
			));
		}	
    }
    public function delete($id)
    {
       
    }
}